<?php

class Application_Model_Grandprix
{
	protected $_gpNum;
	protected $_circuit;
	protected $_gpNom;
	protected $_gpDate;
	protected $_gpNbTours;
	protected $_gpDateMaj;
	protected $_gpCommentaire;
	protected $_course;

	public function __construct(array $options = null)
	{
		if(is_array($options))
		{
			$this->setOptions($options);
		}
	}
	
	public function __set($name, $value)
	{
		$method = 'set' . $name;
		if(('mapper' == $name) || !method_exists($this, $method))
		{
			throw new Exception('Invalid grandprix property');
		}
		$this->$method($value);
	}
	public function __get($name)
	{
		$method = 'get' . $name;
		if(('mapper' == $name) || !method_exists($this, $method))
		{
			throw new Exception('Invalid grandprix property');
		}
		return $this->$method();
	}

	public function setOptions(array $options)
	{
		$methods = get_class_methods($this);
		foreach ($options as $key => $value)
		{
			$method = 'set' . ucfirst($key);
			if(in_array($method, $methods))
			{
				$this->$method($value);
			}
		}
		return $this;
    }
	
	public function setGpNum($gpNum)
	{
		$this->_gpNum = (int)$gpNum;
		return $this;
	}
	public function getGpNum()
	{
		return $this->_gpNum;
	}

	public function setCircuit($circuit)
	{
		$this->_circuit = $circuit;
		return $this;
	}
	public function getCircuit()
	{
		return $this->_circuit;
	}

	public function setGpNom($gpNom)
	{
		$this->_gpNom = (string)$gpNom;
		return $this;
	}
	public function getGpNom()
	{
		return $this->_gpNom;
	}

	public function setGpDate($gpDate)
	{
		$this->_gpDate = (string)$gpDate;
		return $this;
	}
	public function getGpDate()
	{
		return $this->_gpDate;
	}

	public function setGpNbTours($gpNbTours)
	{
		$this->_gpNbTours = (int)$gpNbTours;
		return $this;
	}
	public function getGpNbTours()
	{
		return $this->_gpNbTours;
	}

	public function setGpDateMaj($gpDateMaj)
	{
		$this->_gpDateMaj = (string)$gpDateMaj;
		return $this;
	}
	public function getGpDateMaj()
	{
		return $this->_gpDateMaj;
	}

	public function setGpCommentaire($gpCommentaire)
	{
		$this->_gpCommentaire = (string)$gpCommentaire;
		return $this;
	}
	public function getGpCommentaire()
	{
		return $this->_gpCommentaire;
	}
	
	public function setCourse($course)
	{
		$this->_course = $course;
		return $this;
	}
	public function getCourse()
	{
		return $this->_course;
	}
	
	public function toArray()
	{
		$tab = array();
		$tab['gpnum']=$this->_gpNum;
		if(!is_null($this->_circuit))
		{
			$tab['cirnum']=$this->_circuit->getCirNum();
		}
		$tab['gpnom']=$this->_gpNom;
		$tab['gpdate']=date('Y-m-d',strtotime($this->_gpDate));
		$tab['gpnbtours']=$this->_gpNbTours;
		$tab['gpcommentaire']=$this->_gpCommentaire;
		
		return $tab;
	}
}